package com.electronicmallapiidea;

import com.electronicmallapiidea.entity.User;
import com.electronicmallapiidea.mapper.UserMapper;
import com.electronicmallapiidea.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@SpringBootTest
public class Demo01_BaseMapper {

    private UserService userService;
    @Autowired
    private UserMapper userMapper;
//    插入
    @Test
    public void insert(){
        for (int i = 0; i < 10; i++) {
            User user = new User(null, "wrk"+i, i+"", "2332", "fjdslf", "fjdslf", "dfjsd", "fjdsf", "fjskdf");
            userMapper.insert(user);
        }

    }
//  修改
    @Test
    public void uddate(){
        User user = new User(3, "wrkwrk", "1221", "2332", "fjdslf", "fjdslf", "dfjsd", "fjdsf", "fjskdf");
        userMapper.updateById(user);
    }
    //  根据id查询
    @Test void selectByID(){
        System.out.println(userMapper.selectById(3));
    }

    //  根据一批id查询
    @Test void selectBatchIds(){
        String[] ids={"2","1"};
        List<User> list = userMapper.selectBatchIds(Arrays.asList(ids));
        System.out.println(list);
//        System.out.println(userMapper.selectBatchIds(Arrays.asList(ids)));
    }


//    根据条件查询数据
// 根据条件查询,map中的多个条件是并列关系
    @Test
    void selectByMap(){
        HashMap<String, Object> param = new HashMap<>();
        param.put("id",1);
        param.put("username","admin");
        System.out.println(userMapper.selectByMap(param));
    }

    //根据id删除
    @Test
    void deleteById(){
        System.out.println(userMapper.deleteById(5));
    }

//    根据id批量删除数据
    @Test
    void deleteBatchIds(){
        String[] ids={"2","1"};
        System.out.println();
    }
//      根据条件删除数据
    @Test
    void deleteByMap(){
        HashMap<String, Object> param = new HashMap<>();
        param.put("username","wrk1");
        param.put("nickname","2332");
        int i = userMapper.deleteByMap(param);
        System.out.print(i);
    }

}
